<?php
require_once ROOT_ADMIN_MODELS.DS.'Models_Base.php';
class Models_Typenews extends Models_Base{
	public function __construct(){
		parent::__construct();
		$this->_key="id";
		$this->_table="typenews";
	}
	public function listtypenews($forum_id,$sort)
	{
		$sql="	SELECT *
				FROM typenews
				WHERE forum_id ={$forum_id} AND status != -1 ";
		if($sort != "")
			$sql .= " AND status != 0";
		$sql .= " ORDER BY number";
		$data=$this->_db->fetchAll($sql,null,Zend_Db::FETCH_OBJ);
		return $data;
	}
	
	public function gettypenewsByid($id)
	{
		$sql = "SELECT * FROM typenews WHERE id = $id AND status != -1";
		$data = $this->_db->fetchRow($sql);
		return $data;
	}
	
	public function updatenumber($id,$number)
	{
		$sql = "UPDATE typenews SET number = $number WHERE id = $id";
		$this->_db->query($sql);
	}
	
	public function setstatus($id,$status)
	{
		$sql = "UPDATE typenews SET status = $status WHERE id = $id";
		$this->_db->query($sql);
	}
	
	public function del($id){
		$sql = "DELETE FROM typenews WHERE id = $id";
		$this->_db->query($sql);
	}
	
	public function countnews($id){
		$sql = "SELECT COUNT(id) FROM news WHERE typeNews_id = $id";
		$count = $this->_db->fetchOne($sql);
		return $count;
	}
}
